﻿using SharedClassLibrary.DTOs;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace SharedClassLibrary.HttpRequest
{
    public class ApiClient
    {
        private readonly HttpClient httpClient;
        private readonly ApiClientOptions options;

        public ApiClient(HttpClient httpClient, ApiClientOptions options)
        {
            this.httpClient = httpClient;
            this.options = options;
            this.httpClient.BaseAddress = new Uri(options.Address);
        }

        public async Task<LoginResponse> GetAsync(CancellationToken token = default)
        {
            var response = await httpClient.PostAsync($"/login", Generics.GenerateStringContent(Generics.SerializeObject(new LoginDTO { UserName = "admin", Password = "admin" })));
            var returnObject = await response.Content.ReadAsStringAsync();
            return Generics.DeserializeJsonString<LoginResponse>(returnObject);
        }
    }
}
